const express = require('express');
const router = express.Router();
const StudentClub = require('../../models/studentClub/studentClub');

// 删除学生申请的社团记录
router.delete('/delectSClub', async (req, res) => {
  const { student_id, club_id } = req.body;

  if (!student_id || !club_id) {
    return res.status(400).json({ message: '缺少必要参数 student_id 或 club_id' });
  }

  try {
    const deleted = await StudentClub.destroy({
      where: {
        student_id,
        club_id
      }
    });

    if (deleted) {
      res.status(200).json({ message: '删除成功' });
    } else {
      res.status(404).json({ message: '未找到对应的申请记录' });
    }
  } catch (error) {
    console.error('删除社团申请记录出错：', error);
    res.status(500).json({ message: '服务器错误，请稍后重试' });
  }
});
// ✅ 根据 id 删除学生社团记录
router.delete('/delectSClubById/:id', async (req, res) => {
    const { id } = req.params;
  
    try {
      const deleted = await StudentClub.destroy({
        where: { id }
      });
  
      if (deleted) {
        res.status(200).json({ message: '根据ID删除成功' });
      } else {
        res.status(404).json({ message: '未找到对应的记录' });
      }
    } catch (error) {
      console.error('根据ID删除社团申请记录出错：', error);
      res.status(500).json({ message: '服务器错误，请稍后重试' });
    }
  });
module.exports = router;
